package com.problem.leetcode;

import java.util.Stack;

/**
 * Problem232
 *
 * @author didi
 * @DESCRIPTION
 * @create 2019-05-20 19:14
 **/

class MyQueue {

    private Stack<Integer> push;
    private Stack<Integer> pop;

    /**
     * Initialize your data structure here.
     */
    public MyQueue() {
        push = new Stack<>();
        pop = new Stack<>();
    }

    /**
     * Push element x to the back of queue.
     */
    public void push(int x) {
        while (!pop.empty()) {
            push.push(push.pop());
        }
        push.push(x);
    }

    /**
     * Removes the element from in front of queue and returns that element.
     */
    public int pop() {
        while (!push.empty()) {
            pop.push(push.pop());
        }
        return pop.pop();
    }

    /**
     * Get the front element.
     */
    public int peek() {
        while (!push.empty()) {
            pop.push(push.pop());
        }
        return pop.peek();
    }

    /**
     * Returns whether the queue is empty.
     */
    public boolean empty() {
        return pop.empty() && push.empty();
    }
}

